<?php

/**
 * Application Models
 *
 * @package Application_Model
 * @subpackage Model
 * @author markos
 * @copyright ZF model generator
 * @license http://framework.zend.com/license/new-bsd     New BSD License
 */


/**
 * 
 *
 * @package Application_Model
 * @subpackage Model
 * @author markos
 */
class Application_Model_MiembroLaboratorio extends Application_Model_ModelAbstract
{

    /**
     * Database var type int(10) unsigned
     *
     * @var int
     */
    protected $_CodigoLaboratorio;

    /**
     * Database var type varchar(50)
     *
     * @var string
     */
    protected $_UsernameCreador;

    /**
     * Database var type varchar(50)
     *
     * @var string
     */
    protected $_Username;

    /**
     * Database var type int(10) unsigned
     *
     * @var int
     */
    protected $_CodigoRol;

    /**
     * Database var type timestamp
     *
     * @var string
     */
    protected $_FechaCreacion;


    /**
     * Parent relation miembro_laboratorio_ibfk_1
     *
     * @var Application_Model_Laboratorio
     */
    protected $_Laboratorio;

    /**
     * Parent relation miembro_laboratorio_ibfk_2
     *
     * @var Application_Model_Usuario
     */
    protected $_Usuario;

    /**
     * Parent relation miembro_laboratorio_ibfk_3
     *
     * @var Application_Model_Rol
     */
    protected $_Rol;

    /**
     * Parent relation miembro_laboratorio_ibfk_4
     *
     * @var Application_Model_Usuario
     */
    protected $_Usuario;


    /**
     * Sets up column and relationship lists
     */
    public function __construct()
    {
        parent::init();
        $this->setColumnsList(array(
            'codigo_laboratorio'=>'CodigoLaboratorio',
            'username_creador'=>'UsernameCreador',
            'username'=>'Username',
            'codigo_rol'=>'CodigoRol',
            'fecha_creacion'=>'FechaCreacion',
        ));

        $this->setParentList(array(
            'MiembroLaboratorioIbfk1'=> array(
                    'property' => 'Laboratorio',
                    'table_name' => 'Laboratorio',
                ),
            'MiembroLaboratorioIbfk2'=> array(
                    'property' => 'Usuario',
                    'table_name' => 'Usuario',
                ),
            'MiembroLaboratorioIbfk3'=> array(
                    'property' => 'Rol',
                    'table_name' => 'Rol',
                ),
            'MiembroLaboratorioIbfk4'=> array(
                    'property' => 'Usuario',
                    'table_name' => 'Usuario',
                ),
        ));

        $this->setDependentList(array(
        ));
    }

    /**
     * Sets column codigo_laboratorio
     *
     * @param int $data
     * @return Application_Model_MiembroLaboratorio
     */
    public function setCodigoLaboratorio($data)
    {
        $this->_CodigoLaboratorio = $data;
        return $this;
    }

    /**
     * Gets column codigo_laboratorio
     *
     * @return int
     */
    public function getCodigoLaboratorio()
    {
        return $this->_CodigoLaboratorio;
    }

    /**
     * Sets column username_creador
     *
     * @param string $data
     * @return Application_Model_MiembroLaboratorio
     */
    public function setUsernameCreador($data)
    {
        $this->_UsernameCreador = $data;
        return $this;
    }

    /**
     * Gets column username_creador
     *
     * @return string
     */
    public function getUsernameCreador()
    {
        return $this->_UsernameCreador;
    }

    /**
     * Sets column username
     *
     * @param string $data
     * @return Application_Model_MiembroLaboratorio
     */
    public function setUsername($data)
    {
        $this->_Username = $data;
        return $this;
    }

    /**
     * Gets column username
     *
     * @return string
     */
    public function getUsername()
    {
        return $this->_Username;
    }

    /**
     * Sets column codigo_rol
     *
     * @param int $data
     * @return Application_Model_MiembroLaboratorio
     */
    public function setCodigoRol($data)
    {
        $this->_CodigoRol = $data;
        return $this;
    }

    /**
     * Gets column codigo_rol
     *
     * @return int
     */
    public function getCodigoRol()
    {
        return $this->_CodigoRol;
    }

    /**
     * Sets column fecha_creacion
     *
     * @param string $data
     * @return Application_Model_MiembroLaboratorio
     */
    public function setFechaCreacion($data)
    {
        $this->_FechaCreacion = $data;
        return $this;
    }

    /**
     * Gets column fecha_creacion
     *
     * @return string
     */
    public function getFechaCreacion()
    {
        return $this->_FechaCreacion;
    }

    /**
     * Sets parent relation CodigoLaboratorio
     *
     * @param Application_Model_Laboratorio $data
     * @return Application_Model_MiembroLaboratorio
     */
    public function setLaboratorio(Application_Model_Laboratorio $data)
    {
        $this->_Laboratorio = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['codigo_laboratorio'];
        }

        $this->setCodigoLaboratorio($primary_key);

        return $this;
    }

    /**
     * Gets parent CodigoLaboratorio
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Laboratorio
     */
    public function getLaboratorio($load = true)
    {
        if ($this->_Laboratorio === null && $load) {
            $this->getMapper()->loadRelated('MiembroLaboratorioIbfk1', $this);
        }

        return $this->_Laboratorio;
    }

    /**
     * Sets parent relation Username
     *
     * @param Application_Model_Usuario $data
     * @return Application_Model_MiembroLaboratorio
     */
    public function setUsuario(Application_Model_Usuario $data)
    {
        $this->_Usuario = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['username'];
        }

        $this->setUsername($primary_key);

        return $this;
    }

    /**
     * Gets parent Username
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Usuario
     */
    public function getUsuario($load = true)
    {
        if ($this->_Usuario === null && $load) {
            $this->getMapper()->loadRelated('MiembroLaboratorioIbfk2', $this);
        }

        return $this->_Usuario;
    }

    /**
     * Sets parent relation CodigoRol
     *
     * @param Application_Model_Rol $data
     * @return Application_Model_MiembroLaboratorio
     */
    public function setRol(Application_Model_Rol $data)
    {
        $this->_Rol = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['codigo_rol'];
        }

        $this->setCodigoRol($primary_key);

        return $this;
    }

    /**
     * Gets parent CodigoRol
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Rol
     */
    public function getRol($load = true)
    {
        if ($this->_Rol === null && $load) {
            $this->getMapper()->loadRelated('MiembroLaboratorioIbfk3', $this);
        }

        return $this->_Rol;
    }

    /**
     * Sets parent relation UsernameCreador
     *
     * @param Application_Model_Usuario $data
     * @return Application_Model_MiembroLaboratorio
     */
    public function setUsuario(Application_Model_Usuario $data)
    {
        $this->_Usuario = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['username'];
        }

        $this->setUsernameCreador($primary_key);

        return $this;
    }

    /**
     * Gets parent UsernameCreador
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Usuario
     */
    public function getUsuario($load = true)
    {
        if ($this->_Usuario === null && $load) {
            $this->getMapper()->loadRelated('MiembroLaboratorioIbfk4', $this);
        }

        return $this->_Usuario;
    }

    /**
     * Returns the mapper class for this model
     *
     * @return Application_Model_Mapper_MiembroLaboratorio
     */
    public function getMapper()
    {
        if ($this->_mapper === null) {
            $this->setMapper(new Application_Model_Mapper_MiembroLaboratorio());
        }

        return $this->_mapper;
    }

    /**
     * Deletes current row by deleting the row that matches the primary key
     *
	 * @see Application_Model_Mapper_MiembroLaboratorio::delete
     * @return int|boolean Number of rows deleted or boolean if doing soft delete
     */
    public function deleteRowByPrimaryKey()
    {
        $primary_key = array();
        if (! $this->getCodigoLaboratorio()) {
            throw new Exception('Primary Key CodigoLaboratorio does not contain a value');
        } else {
            $primary_key['codigo_laboratorio'] = $this->getCodigoLaboratorio();
        }

        if (! $this->getUsername()) {
            throw new Exception('Primary Key Username does not contain a value');
        } else {
            $primary_key['username'] = $this->getUsername();
        }

        return $this->getMapper()->getDbTable()->delete('codigo_laboratorio = '
                    . $this->getMapper()->getDbTable()->getAdapter()->quote($primary_key['codigo_laboratorio'])
                    . ' AND username = '
                    . $this->getMapper()->getDbTable()->getAdapter()->quote($primary_key['username']));
    }
}
